﻿namespace BlamanticUI.Components;

/// <summary>
/// Render a button with '&lt;button>' HTML tag.
/// </summary>
[HtmlTag("button")]
[CssClass("button", Order = 500)]
public class Button : BlazorChildContentComponentBase,
    IHasUIComponent,
    IHasColor,
    IHasSize,
    IHasVertical,
    IHasActive,
    IHasDisabled,
    IHasLoading,
    IHasFluid,
    IHasCircular,
    IHasAttatched,
    IHasAnimated,
    IHasInverted,
    IHasFloated
{
    /// <summary>
    /// Initializes a new instance of the <see cref="Button"/> class.
    /// </summary>
    public Button()
    {

    }

    /// <summary>
    /// Gets or sets the emphasis style.
    /// </summary>
    [Parameter] [CssClass] public Emphasis? Emphasis { get; set; }

    /// <summary>
    /// Provides different kinds of style of button.
    /// </summary>
    [Parameter] public ButtonStyle Style { get; set; } = ButtonStyle.Default;

    /// <summary>
    /// Gets or sets a value indicating whether this is animated.
    /// </summary>
    /// <value>
    ///   <c>true</c> if animated; otherwise, <c>false</c>.
    /// </value>
    [Parameter] public bool Animated { get; set; }
    /// <summary>
    /// Gets or sets a value indicating whether this is a fade animation.
    /// </summary>
    [Parameter] [CssClass] public bool Fade { get; set; }
    /// <summary>
    /// Gets or sets a color.
    /// </summary>
    [Parameter] public Color? Color { get; set; }
    /// <summary>
    /// Gets or sets dark style.
    /// </summary>
    [Parameter] public bool Inverted { get; set; }
    /// <summary>
    /// Gets or sets the size.
    /// </summary>
    [Parameter] public Size? Size { get; set; }
    /// <summary>
    /// Gets or sets layout to be vertical.
    /// </summary>
    [Parameter] public bool Vertical { get; set; }
    /// <summary>
    /// Gets or sets outline style.
    /// </summary>
    [Parameter] [CssClass("basic")] public bool Outline { get; set; }

    /// <summary>
    /// Gets or sets the position of icon as label to layout in button.
    /// </summary>
    [Parameter] public HorizontalPosition? IconLabeled { get; set; }
    /// <summary>
    /// Gets or sets button only has icon.
    /// </summary>
    [Parameter] [CssClass("icon")] public bool IconOnly { get; set; }
    /// <summary>
    /// Gets or sets the status is actived.
    /// </summary>
    [Parameter] public bool Active { get; set; }
    /// <summary>
    /// Gets or sets the status is disabled.
    /// </summary>
    [Parameter] public bool Disabled { get; set; }
    /// <summary>
    /// Gets or sets the status is loading.
    /// </summary>
    [Parameter] public bool Loading { get; set; }
    /// <summary>
    /// Gets or sets the width is 100% as parent.
    /// </summary>
    [Parameter] public bool Fluid { get; set; }
    /// <summary>
    /// Gets or sets the circular style.
    /// </summary>
    [Parameter] public bool Circular { get; set; }
    /// <summary>
    /// Gets or sets position that can be attached to another component.
    /// </summary>
    [Parameter] public bool Attached { get; set; }
    /// <summary>
    /// Gets or sets the attached at horizontal position.
    /// </summary>
    [Parameter] [CssClass] public HorizontalPosition? AttachedHorizontal { get; set; }
    /// <summary>
    /// Gets or sets the attached at vertical position.
    /// </summary>
    [Parameter] public VerticalPosition? AttachedVertical { get; set; }
    /// <summary>
    /// Gets or sets the floated position with parent conponent.
    /// </summary>
    [Parameter] public HorizontalPosition? Floated { get; set; }

    /// <summary>
    /// Gets or sets a callback method invoke after actived.
    /// </summary>
    [Parameter] public EventCallback<bool> OnActive { get; set; }
    /// <summary>
    /// Gets or sets a callback method invoke after disabled.
    /// </summary>
    [Parameter] public EventCallback<bool> OnDisabled { get; set; }

    protected override void BuildCssClass(ICssClassBuilder builder)
    {
        if (IconLabeled.HasValue)
        {
            builder.Append($"{IconLabeled.GetCssClass()} labeled icon");
        }
        builder.Append(Style.GetCssClass(), Style != ButtonStyle.Default);
    }
}


/// <summary>
/// The style of button.
/// </summary>
public enum ButtonStyle
{
    /// <summary>
    /// Default style.
    /// </summary>
    Default = 0,
    /// <summary>
    /// Outline style.
    /// </summary>
    [CssClass("basic")] Outline,
    /// <summary>
    /// Underline style.
    /// </summary>
    [CssClass("tertiary")] Underline
}

/// <summary>
/// The empasis of button.
/// </summary>
[System.Flags]
public enum Emphasis
{
    /// <summary>
    /// The primary.
    /// </summary>
    Primary = 1,
    /// <summary>
    /// The secondary.
    /// </summary>
    Secondary = 2,
    /// <summary>
    /// The positive.
    /// </summary>
    Positive = 3,
    /// <summary>
    /// The nagative.
    /// </summary>
    Negative = 4,
}
